package com.atguigu.gmall.search.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.search.Goods;
import com.atguigu.gmall.model.search.vo.SearchParamsVO;
import com.atguigu.gmall.model.search.vo.SearchResultVo;
import com.atguigu.gmall.search.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/inner/search")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    /**
     * 在es中保存商品数据
     * @param goods
     * @return
     */
    @PostMapping("/save")
    public Result saveGoods(@RequestBody Goods goods) {
        goodsService.save(goods);
        return Result.ok();
    }

    /**
     * 在es中移除商品
     * @param skuId
     * @return
     */
    @DeleteMapping("/delete/{skuId}")
    public Result delGoods(@PathVariable Long skuId) {
        goodsService.delete(skuId);
        return Result.ok();
    }


    /**
     * 检索
     * @param param
     * @return
     */
    @PostMapping("/search")
    public Result<SearchResultVo> search(@RequestBody SearchParamsVO param){
        SearchResultVo resultVo =  goodsService.search(param);
        return Result.ok(resultVo);
    }


    /**
     * 修改浏览量
     * @param skuId
     * @param hotScore
     * @return
     */
    @GetMapping("/incrHotScore/{skuId}/{hotScore}")
    public Result incrHotScore(@PathVariable Long skuId, @PathVariable Long hotScore) {
        goodsService.incrHotScore(skuId, hotScore);
        return Result.ok();
    }



}
